import { Controller, Get, Post, Body, Patch, Param, Delete, HttpCode, Query, UseGuards } from '@nestjs/common';
import { BannerService } from './banner.service';
import { AuthGuard } from '@nestjs/passport';
import { ApiResponse, ApiOperation, ApiBody, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { IdDto } from 'src/common/dto/dto';
import { GetBannerDto, CreateBannerDto, UpdateBannerDto } from './dto/banner.dto';
import { BannerResult } from './entities/banner.entity';

@ApiBearerAuth() // swagger文档设置token
@ApiTags('轮播图')
@Controller('admin/banner')
export class BannerController {
  constructor(private readonly bannerService: BannerService) { }
  /** 轮播图 */
  @HttpCode(200)
  @Get('/getBannerPage')
  @ApiResponse({
    status: 200,
    description: '轮播图列表',
    type: BannerResult,
  })
  @ApiOperation({
    tags: ['获取轮播图'],
    summary: '获取轮播图',
    operationId: 'getBannerPage',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  getBannerPage(@Query() params: GetBannerDto) {
    return this.bannerService.getBannerPage(params);
  }
  @HttpCode(200)
  @Post('/createBanner')
  @ApiBody({
    description: '创建轮播图',
    type: CreateBannerDto,
  })
  @ApiOperation({
    summary: '创建轮播图',
    operationId: 'createBanner',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async createBanner(@Body() body: CreateBannerDto) {
    return this.bannerService.createBanner(body);
  }
  @HttpCode(200)
  @Post('/updateBanner')
  @ApiBody({
    description: '更新轮播图信息',
    type: UpdateBannerDto,
  })
  @ApiOperation({
    summary: '更新轮播图信息',
    operationId: 'updateBanner',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async updateBanner(@Body() body: UpdateBannerDto) {
    return this.bannerService.updateBanner(body);
  }
  @HttpCode(200)
  @Post('/deleteBanner')
  @ApiBody({
    description: '删除轮播图',
    type: IdDto,
  })
  @ApiOperation({
    summary: '删除轮播图',
    operationId: 'deleteBanner',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async deleteBanner(@Body() body: IdDto) {
    return this.bannerService.deleteBanner(body);
  }
}
